package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 * The purpose of the sub-parameter B1 protocol is to specify the physical
 * layer and framing used for this connection.
 */
public enum B1Protocol
        implements ByteBufferWritable {

    /**
     * 64 kbit/s with HDLC framing (default).
     */
    HDLC_FRAMING_64KBITPS(0),

    /**
     * 64 kbit/s bit-transparent operation with byte framing from the network.
     */
    BIT_TRANSPARENT_64KBITPS(1),

    /**
     * V.110 asynchronous operation with start/stop byte framing (see Note 1).
     */
    V110_ASYNCHRONOUS(2),

    /**
     * V.110 synchronous operation with HDLC framing (see Note 2).
     */
    V110_SYNCHRONOUS(3),

    /**
     * T.30 modem for Group 3 fax.
     */
    T30_MODEM(4),

    /**
     * 64 kbit/s inverted with HDLC framing.
     */
    INVERTED_64KBITPS(5),

    /**
     * 56 kbit/s bit-transparent operation with byte framing from the network.
     */
    BIT_TRANSPARENT_56KBITPS(6),

    /**
     * Modem with full negotiation(B2 Protocol must be 7).
     */
    MODEM_WITH_FULL_NEGOTIATION(7),

    /**
     * Modem asynchronous operation with start/stop byte framing.
     */
    MODEM_ASYNCHRONOUS(8),

    /**
     * Modem synchronous operation with HDLC framing.
     */
    MODEM_SYNCHRONOUS(9);

    B1Protocol(final int value) {
        _value = (short) value;
    }

    /**
     *
     * @return
     */
    public short getValue() {
        return _value;
    }

    private short _value;

    /** {@inheritDoc} */
    public void writeTo(final ByteBuffer byteBuffer) {
        byteBuffer.putShort(_value);
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format("%s(%s)",
                name(),
                getValue());

        return s;
    }

}
